package com.ckx.图形;

import java.util.Scanner;

public class Test {
    public static void drawMap(Shape shape){
        shape.draw();
    }
//        改良版，利用多态
    public static void main(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Triangle triangle = new Triangle();
        Shape[] shapes={cycle,rect,triangle};
        for(Shape shape:shapes){
            shape.draw();
        }
    }
    public static void main2(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Triangle triangle = new Triangle();
        String [] arr=new String[]{"cycle","rect","triangle"};
        for (String s:arr){
            if(s.equals("cycle")){
                cycle.draw();
            }
            else if(s.equals("rect")){
                rect.draw();
            }
            else {
                triangle.draw();
            }
        }
    }
    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Triangle triangle = new Triangle();

//        drawMap(new Cycle()); 匿名对象


        drawMap(rect);
        drawMap(cycle);
        drawMap(triangle);
    }
}
